package zcw.com.lib_leet_code;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 朱城委 on 2022/2/11.<br><br>
 *
 * 简单：最小栈
 */
public class Topic155 {

}

class MinStack {

    private final List<Integer> list;
    private final List<Integer> minList;

    public MinStack() {
        list = new ArrayList<>();
        minList = new ArrayList<>();
    }

    public void push(int val) {
        list.add(val);
        if(minList.isEmpty() || val < minList.get(minList.size() - 1)) {
            minList.add(val);
        }
        else {
            minList.add(minList.get(minList.size() - 1));
        }
    }

    public void pop() {
        list.remove(list.size() - 1);
        minList.remove(minList.size() - 1);
    }

    public int top() {
        return list.get(list.size() - 1);
    }

    public int getMin() {
        return minList.get(minList.size() - 1);
    }
}